<?php
/**
 * Description of smartyManager
 *
 * @author del Valle, Federico <quaidy@gmail.com>
 */
class smartyManager {
  /**
   *
   * @var smarty
   */
    private static $smarty = null;

    /**
     * Devuelve un objeto smarty ya configurado
     *
     * @return smarty
     */
    public static function tomar() {
      if (self::$smarty == null) {
        self::$smarty = new Smarty();
        self::configurar();
        return self::$smarty;
      } else {
        return self::$smarty;
      }
    }

    /**
     * Configura smarty segun el config.ini
     */
    private static function configurar() {
      $carpetas = configManager::obtener("smarty");
     
      if (configManager::obtener("general","devmode")) {
        //self::$smarty->debugging = (bool)configManager::obtener("dev","debug"); //TODO no se muestra el debug de smarty
        self::$smarty->caching = (bool)configManager::obtener("general","tplcache");
      }

      $templates_ruta = smarty_crear_rutas($carpetas["templates"]);
      if (!empty($_SESSION["PATH"]) && $_SESSION["PATH"] != "principal") {
        $entorno = "../";
      } else {
        $entorno = "";
      }
      self::$smarty->template_dir = $templates_ruta;
      self::$smarty->compile_dir = realpath($entorno."../".$carpetas["templates_c"]);
      self::$smarty->cache_dir = realpath($entorno."../".$carpetas["cache"]);
      self::$smarty->config_dir = realpath($entorno."../".$carpetas["configs"]);
    }
}
?>
